package com.dabaozhan.modules.wx_app.service.impl;

import com.dabaozhan.common.utils.OmsPage;
import com.dabaozhan.common.utils.Utils;
import com.dabaozhan.modules.wx_app.dao.AccountLogMapper;
import com.dabaozhan.modules.wx_app.entity.AccountLogEntity;
import com.dabaozhan.modules.wx_app.service.AccountLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author houzhong
 * @date 2018-12-29 11:42
 */
@Service("accountLogService")
public class AccountLogServiceImpl implements AccountLogService {

    @Autowired
    private AccountLogMapper accountLogMapper;

    @Override
    public int saveSiteAccountLog(AccountLogEntity v) {
        if (v.getId() == null) {
            v.setId(Utils.id().toString());
        }
        return accountLogMapper.save(v);
    }

    @Override
    public int updateSiteAccountLog(AccountLogEntity v) {

        return accountLogMapper.update(v);
    }

    @Override
    public int findByAccountLogCount(AccountLogEntity accountLog) {
        return accountLogMapper.findByAccountLogCount(accountLog);
    }

    @Override
    public OmsPage<AccountLogEntity> findByAccountLog(AccountLogEntity accountLog, Integer page, Integer size) {
        OmsPage<AccountLogEntity> pages = new OmsPage<AccountLogEntity>();
        pages.setTotal(accountLogMapper.findByAccountLogCount(accountLog));
        List<AccountLogEntity> list = accountLogMapper.findByAccountLog(accountLog,page = (page - 1) * size,size);
        pages.setResult(list);
        return pages;
    }
}
